package com.example.test.mapper;

import com.example.test.bean.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MessageMapper {

    /**
     * 新增聊天记录
     * @param message
     * @return
     */
    @Insert("insert into messages(information,studentId,teacherId,time,storyId,fromToState) values(#{information},#{studentId},#{teacherId},#{time},#{storyId},#{fromToState})")
    @Options(useGeneratedKeys = true, keyProperty = "chatId", keyColumn = "id")/*增加这个注解插入记录后会返回自增长的id*/
    public int insertMessage(Message message);

    /**
     * 查询聊天记录
     * @param storyId
     * @return
     */
    @Select("select * from messages where storyId = #{storyId} order by time asc")
    List<Message> selectMessageList(int storyId);

    /**
     * 查询所有小事读取信息的个数
     * @return
     */
    @Select("select count(status) from messages where status = 0 and storyId = #{storyId}")
    Integer selectStoryStatusCount(@Param("storyId") int storyId);
}
